#!/bin/bash

set -x
#此脚本执行环境是在启动的容器中执行的
CUR_DIR=$(pwd)
WORK_DIR=$1

echo "current dir: $CUR_DIR, work dir: $WORK_DIR" >> $1/result.log

git clone -b develop http://root:glpat-tWyMPqC9_3PVzz9kcoBB@10.15.3.7/dcutoolkit/driverruntime/rocprofiler.git

cd rocprofiler
rm -rf build && mkdir build
cd build
export CMAKE_LD_AQLPROFILE=1
cmake \
    -DROCM_PATH=${ROCM_PATH} \
    -DCMAKE_PREFIX_PATH=$ROCM_PATH \
    -DCMAKE_MODULE_PATH=$ROCM_PATH/hip/cmake \
    -DGPU_TARGETS="gfx906;gfx926;gfx928;gfx936" \
    -DCPACK_OBJCOPY_EXECUTABLE="${ROCM_PATH}/llvm/bin/llvm-objcopy" \
    -DCPACK_READELF_EXECUTABLE="${ROCM_PATH}/llvm/bin/llvm-readelf" \
    -DCPACK_STRIP_EXECUTABLE="${ROCM_PATH}/llvm/bin/llvm-strip" \
    -DCPACK_OBJDUMP_EXECUTABLE="${ROCM_PATH}/llvm/bin/llvm-objdump" \
    -DCMAKE_INSTALL_LIBDIR=lib \
    -DCPACK_PACKAGING_INSTALL_PREFIX=${ROCM_PATH}/rocprofiler \
    ..
make -j$(nproc) && make mytest && make install

# 7、执行测试
./run.sh  # 执行v1测试
./run_tests.sh  # 执行v2测试